/*******************************************************************************
 * 
 * this file is for ld4s project
 * 
 * here is the everything about cookie which you would get
 * 
 * depended on utility.js
 * 
 * 
 * usage:UserFactory.save() save all information
 * 
 * 
 */

// defined struct of this User class
function UserFactory() {
	var _t = this;

	function UserObj() {
		this.userName = null;
		this.password = null;
		this.email = null;
	}

	this.LoadingCookie = function() {
		if ($.cookie("ld4s_Account") != undefined && $.cookie("ld4s_Account") != null
				&& $.cookie("ld4s_Account") != "null") {
			return jQuery.parseJSON($.cookie("ld4s_Account"));
		} else {
			return new UserObj();
		}

	};

	this.save = function() {
		$.cookie("ld4s_Account", JSON.stringify(User), {
			path : '/',
			// domain: 'example.com',
			expires : 1
		// time
		});// expires date change here
	};

	this.clear = function() {
		$.cookie("ld4s_Account", null, {
			path : '/'
		});// clear cookie

	};

	this.checkLogin = function() {
		if (window.User != undefined && window.User != null && window.User.userName != null
				&& window.User.password != null) {

			return true;
		} else {
			return false;

		}
	};
}

var UserFactory = window.UserFactory = new UserFactory();
var User = window.User = UserFactory.LoadingCookie();
